﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace P2P_Backup.archive
{
    public class DataFile : File
    {

        byte[] bytes;
        MemoryStream stream;

        public DataFile(RemotePeer peer)
        {
            this.Path = "data";
            this.BackupPeer = peer;
        }
        public void GenerateXml()
        {
            Folder folder = P2PBackup.Instance.MyArchive.getFolderForPeer(BackupPeer);
            string xml = Storage.GetRestoreXML(folder);
            this.bytes = tools.net.getBytes(xml);

            this.Size = bytes.Length;
            this.stream = new MemoryStream(bytes);
        }
        public void DoRestore()
        {
                Folder folder = Storage.GetRestoreFolder(stream);
                new Restore(folder);
        }
        public override Stream GetWritableStream()
        {
            stream = new MemoryStream();
            return stream;
        }
        public override Stream GetReadableStream()
        {
            return stream;
        }

    }
}
